package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理计划
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划接口")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;
    @GetMapping("/all")
    @ApiOperation(value = "查询所有接口")
    public ResponseResult<NursingPlanVo> getAll(){
        List<NursingPlanVo> allPlan=nursingPlanService.getAll();
        return success(allPlan);
    }


    @GetMapping
    @ApiOperation("条件分页查询")
    public ResponseResult pageQuery(
            @ApiParam("护理计划名称") String name,
            @ApiParam("护理计划状态") Integer status,
            @ApiParam(value = "当前页",defaultValue = "1") Integer pageNum,
            @ApiParam(value = "页面大小",defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingPlanVo> plans=nursingPlanService.pageQuery(name,status,pageNum,pageSize);
        return success(plans);
    }

    @GetMapping("{id}")
    @ApiOperation("根据id查询")
    public ResponseResult getById(
            @ApiParam("id")@PathVariable Long id){
        NursingPlanVo nursingPlanVo=nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("新增")
    public ResponseResult add(@ApiParam("护理计划接受类")@RequestBody NursingPlanDto nursingPlanDto){
        int row=nursingPlanService.addPlan(nursingPlanDto);
        return toAjax(row);
    }


    @DeleteMapping("{id}")
    @ApiOperation("删除")
    public ResponseResult deleteById( @ApiParam("id") @PathVariable Long id){
        int row=nursingPlanService.deleteById(id);
        return toAjax(row);
    }

    @PutMapping("/{id}/{status}")
    @ApiOperation("修改状态")
    public ResponseResult updateStatus( @ApiParam("id")@PathVariable Long id, @ApiParam("status")@PathVariable Integer status){
        int row=nursingPlanService.updateStatus(id,status);
        return toAjax(row);
    }

    @PutMapping
    @ApiOperation("修改")
    public ResponseResult update(
            @ApiParam("护理计划")@RequestBody NursingPlanDto nursingPlanDto
    ){
        int row=nursingPlanService.update(nursingPlanDto);
        return toAjax(row);
    }
}
